package com.fulihui.systemcore.dal.convertor;

import java.util.List;
import java.util.stream.Collectors;

import org.near.toolkit.common.DateUtils;
import org.springframework.beans.BeanUtils;

import com.fulihui.systemcore.dal.dataobj.Menu;
import com.fulihui.systemcore.dto.MenuDTO;

/**
 * 
 * @author leeson 2016年5月17日 下午1:43:19
 *
 */
public class MenuConv {
    private static final String[] ignore = { "gmtCreate", "gmtModified" };

    public static Menu convert2DO(MenuDTO mo_) {
        if (mo_ == null) {
            return null;
        }

        Menu do_ = new Menu();
        BeanUtils.copyProperties(mo_, do_, ignore);

        do_.setGmtCreate(mo_.parseGmtCreate());
        do_.setGmtModified(mo_.parseGmtModified());

        return do_;
    }

    public static MenuDTO convert2DTO(Menu do_) {
        if (do_ == null) {
            return null;
        }

        MenuDTO mo_ = new MenuDTO();
        BeanUtils.copyProperties(do_, mo_, ignore);

        mo_.setGmtCreate(DateUtils.formatNewFormat(do_.getGmtCreate()));
        mo_.setGmtModified(DateUtils.formatNewFormat(do_.getGmtModified()));

        return mo_;
    }

    public static List<MenuDTO> convert2List(List<Menu> list) {
        return list.stream().map(MenuConv::convert2DTO).collect(Collectors.toList());
    }
}